'''
Created on 11/01/2013

@author: Jorge
'''
from Classifier import Classifier
import numpy as np
from sklearn.naive_bayes import BernoulliNB
from sklearn.metrics import classification_report
from sklearn.metrics import f1_score, confusion_matrix
from TF_IDF import TF_IDF
from feature_selection.OptimalFeatureForClassifiers import FeaturesForBernoulliNB

from feature_selection.BinormalSeparationWithRandRoubin import BinormalSeparationWithRandRoubin

class BernoulliNaiveBayes(Classifier):
    '''
    classdocs
    '''
 
    def train(self, X, Y):
        x = np.array(X)
        y = np.array(Y)
        tuned_parameters = [{
                             'alpha': np.array(range(1,11,1))/10.0,
                             },
                            ]
        self.model = self.get_optimal_model(BernoulliNB(),tuned_parameters, x,y);
        self.model.fit(x, y)
        
    def test(self, X, Y):
        x = np.array(X) 
        predictions  = self.model.predict(x)
        f1 = f1_score(Y, predictions)
        print ' f1: ',f1
        print ' confusion matrix \n' , confusion_matrix(Y, predictions)
        print classification_report(Y, predictions)
        return f1

if __name__ == '__main__':
    classifier = BernoulliNaiveBayes()
    #classifier.add_transformation_to_data(TF_IDF()) 
    #classifier.add_transformation_to_data(NormalizeData())
    #classifier.setFeatureSelector(BinormalSeparationWithRandRoubin(1800))
    #classifier.setFeatureSelector(FeaturesForBernoulliNB())
    classifier.run_train_and_test()
    #classifier.run_train_and_validation()
    #classifier.optimal_num_feature("bernoulliNB_rest")